package com.douqu.game.core.config.talent;

import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.e.E_ValueType;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

/**
 * Created by dengbo on 2018/10/17 0017.
 */
public class TalentRefineConfig extends GameObject {

    public int talentId;

    //天赋精炼等级
    public int level;

    /**
     * 精炼条件
     */
    public CommonData[] condition;

    //天赋升级消耗
    public GoodsData[] refineCost;

    //天赋升级消耗
    public GoodsData[] refineCostAsset;

    //天赋重置返还道具
    public GoodsData[] restitution;

    public E_ValueType valueType;

    public int value;

    public int openRestrictions;


    @Override
    public boolean check() {

        if(refineCost == null)
        {
            LogUtils.error("Load TalentRefineConfig check refineCost error -> id:" + id);
            return false;
        }
        if(restitution == null)
        {
            LogUtils.error("Load TalentRefineConfig check restitution error -> id:" + id);
            return false;
        }
        if(refineCostAsset == null)
        {
            LogUtils.error("Load TalentRefineConfig check refineCostAsset error -> id:" + id);
            return false;
        }
        if(condition == null)
        {
            LogUtils.error("Load TalentRefineConfig check condition error -> id:" + id);
            return false;
        }

        return super.check();
    }


    public int getAddValue(int base)
    {
        if(valueType == E_ValueType.RATIO_10000)
            return base * value / 10000;
        else
            return value;
    }


    @Override
    public boolean setVariable(String key, String value)
    {

        if("refineCost".equals(key))
        {
            refineCost = LoadUtils.loadGoodDataToArray(key, value);
            return LoadUtils.checkGoods(refineCost, this.getClass(), key, id);
        }
        else if("refineCostAsset".equals(key))
        {
            refineCostAsset = LoadUtils.loadGoodDataToArray(key, value);
            return LoadUtils.checkGoods(refineCostAsset, this.getClass(), key, id);
        }
        else if("restitution".equals(key))
        {
            restitution = LoadUtils.loadGoodDataToArray(key, value);
            return true;
        }
        else if("condition".equals(key))
        {
            condition = LoadUtils.loadCommonDataToArray(key, value);
            return true;
        }
        else if("valueType".equals(key))
        {
            valueType = E_ValueType.forNumber(Integer.parseInt(value));
            return true;
        }
        else
            return super.setVariable(key, value);
    }
}
